package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

// 了解管理路由规范

func main() {
	r := gin.Default()
	v1 := r.Group("/v1")
	{
		v1.GET("/login", login)
		v1.GET("submit", submit)
	}
	v2 := r.Group("/v2")
	{
		v2.POST( "/login", login)
		v2.POST("submit", submit)
	}

	r.Run(":8000")

	// 分别访问v1 和 v2
	// curl http://localhost:8000/v1/login
	// curl http://localhost:8000/v1/submit
	// curl http://localhost:8000/v2/login -X POST
}
func login(c *gin.Context) {
	name := c.DefaultQuery("name", "tom")
	c.String(200, fmt.Sprintf("hello %s\n", name))
}
func submit(c *gin.Context) {
	name := c.DefaultQuery("name", "jack")
	c.String(200, fmt.Sprintf("hello %s\n", name))
}
